<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.

(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual.  Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: M2 Types</title>

<meta name="description" content="Debugging with GDB: M2 Types">
<meta name="keywords" content="Debugging with GDB: M2 Types">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Modula_002d2.html#Modula_002d2" rel="up" title="Modula-2">
<link href="M2-Defaults.html#M2-Defaults" rel="next" title="M2 Defaults">
<link href="M2-Constants.html#M2-Constants" rel="prev" title="M2 Constants">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="M2-Types"></a>
<div class="header">
<p>
Next: <a href="M2-Defaults.html#M2-Defaults" accesskey="n" rel="next">M2 Defaults</a>, Previous: <a href="M2-Constants.html#M2-Constants" accesskey="p" rel="prev">M2 Constants</a>, Up: <a href="Modula_002d2.html#Modula_002d2" accesskey="u" rel="up">Modula-2</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Modula_002d2-Types"></a>
<h4 class="subsubsection">15.4.9.4 Modula-2 Types</h4>
<a name="index-Modula_002d2-types"></a>

<p>Currently <small>GDB</small> can print the following data types in Modula-2
syntax: array types, record types, set types, pointer types, procedure
types, enumerated types, subrange types and base types.  You can also
print the contents of variables declared using these type.
This section gives a number of simple source code examples together with
sample <small>GDB</small> sessions.
</p>
<p>The first example contains the following section of code:
</p>
<div class="smallexample">
<pre class="smallexample">VAR
   s: SET OF CHAR ;
   r: [20..40] ;
</pre></div>

<p>and you can request <small>GDB</small> to interrogate the type and value of
<code>r</code> and <code>s</code>.
</p>
<div class="smallexample">
<pre class="smallexample">(gdb) print s
{'A'..'C', 'Z'}
(gdb) ptype s
SET OF CHAR
(gdb) print r
21
(gdb) ptype r
[20..40]
</pre></div>

<p>Likewise if your source code declares <code>s</code> as:
</p>
<div class="smallexample">
<pre class="smallexample">VAR
   s: SET ['A'..'Z'] ;
</pre></div>

<p>then you may query the type of <code>s</code> by:
</p>
<div class="smallexample">
<pre class="smallexample">(gdb) ptype s
type = SET ['A'..'Z']
</pre></div>

<p>Note that at present you cannot interactively manipulate set
expressions using the debugger.
</p>
<p>The following example shows how you might declare an array in Modula-2
and how you can interact with <small>GDB</small> to print its type and contents:
</p>
<div class="smallexample">
<pre class="smallexample">VAR
   s: ARRAY [-10..10] OF CHAR ;
</pre></div>

<div class="smallexample">
<pre class="smallexample">(gdb) ptype s
ARRAY [-10..10] OF CHAR
</pre></div>

<p>Note that the array handling is not yet complete and although the type
is printed correctly, expression handling still assumes that all
arrays have a lower bound of zero and not <code>-10</code> as in the example
above.
</p>
<p>Here are some more type related Modula-2 examples:
</p>
<div class="smallexample">
<pre class="smallexample">TYPE
   colour = (blue, red, yellow, green) ;
   t = [blue..yellow] ;
VAR
   s: t ;
BEGIN
   s := blue ;
</pre></div>

<p>The <small>GDB</small> interaction shows how you can query the data type
and value of a variable.
</p>
<div class="smallexample">
<pre class="smallexample">(gdb) print s
$1 = blue
(gdb) ptype t
type = [blue..yellow]
</pre></div>

<p>In this example a Modula-2 array is declared and its contents
displayed.  Observe that the contents are written in the same way as
their <code>C</code> counterparts.
</p>
<div class="smallexample">
<pre class="smallexample">VAR
   s: ARRAY [1..5] OF CARDINAL ;
BEGIN
   s[1] := 1 ;
</pre></div>

<div class="smallexample">
<pre class="smallexample">(gdb) print s
$1 = {1, 0, 0, 0, 0}
(gdb) ptype s
type = ARRAY [1..5] OF CARDINAL
</pre></div>

<p>The Modula-2 language interface to <small>GDB</small> also understands
pointer types as shown in this example:
</p>
<div class="smallexample">
<pre class="smallexample">VAR
   s: POINTER TO ARRAY [1..5] OF CARDINAL ;
BEGIN
   NEW(s) ;
   s^[1] := 1 ;
</pre></div>

<p>and you can request that <small>GDB</small> describes the type of <code>s</code>.
</p>
<div class="smallexample">
<pre class="smallexample">(gdb) ptype s
type = POINTER TO ARRAY [1..5] OF CARDINAL
</pre></div>

<p><small>GDB</small> handles compound types as we can see in this example.
Here we combine array types, record types, pointer types and subrange
types:
</p>
<div class="smallexample">
<pre class="smallexample">TYPE
   foo = RECORD
            f1: CARDINAL ;
            f2: CHAR ;
            f3: myarray ;
         END ;

   myarray = ARRAY myrange OF CARDINAL ;
   myrange = [-2..2] ;
VAR
   s: POINTER TO ARRAY myrange OF foo ;
</pre></div>

<p>and you can ask <small>GDB</small> to describe the type of <code>s</code> as shown
below.
</p>
<div class="smallexample">
<pre class="smallexample">(gdb) ptype s
type = POINTER TO ARRAY [-2..2] OF foo = RECORD
    f1 : CARDINAL;
    f2 : CHAR;
    f3 : ARRAY [-2..2] OF CARDINAL;
END 
</pre></div>

<hr>
<div class="header">
<p>
Next: <a href="M2-Defaults.html#M2-Defaults" accesskey="n" rel="next">M2 Defaults</a>, Previous: <a href="M2-Constants.html#M2-Constants" accesskey="p" rel="prev">M2 Constants</a>, Up: <a href="Modula_002d2.html#Modula_002d2" accesskey="u" rel="up">Modula-2</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
